<template>
    登录页
    <div>
        账号：<input type="text" v-model="accunt" placeholder="请输入你的账号">
    </div>
    <div>
        密码:<input type="password" v-model="password" placeholder="请输入你的密码">
    </div>
    <div><button @click="submit">登录</button></div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { useStore } from 'vuex'

const accunt = ref('')
const password = ref('')

//拿到路由的实例化对象
const router = useRouter()
//拿到Vuex的实例化对象
const store = useStore()

const submit = () => {
    console.log("2222");
    if (accunt.value === 'admin' && password.value === '123456') {
        alert('登录成功')


        //保存用户信息
        store.commit("updateUserInfo", {
            nmae: '张三',
            gender: '男',
            phone: '1345555666'
        })
        //跳转去用户中心页
        router.push({ path: '/user-center' })

    } else {
        alert('账号密码错误，请重新输入')
    }

}
</script>